#include <vector>
#include <memory>
#include "HttpServer.hpp"
#include "Err.hpp"
#include "Util.hpp"

const string SEP = "\r\n";

std::string GetContentType(const std::string &suffix){
    std::string content_type = "Content-Type: ";
    if (suffix == ".html" || suffix == ".htm")
        content_type + "text/html";
    else if (suffix == ".css")
        content_type += "text/css";
    else if (suffix == ".js")
        content_type += "application/x-javascript";
    else if (suffix == ".png")
        content_type += "image/png";
    else if (suffix == ".jpg")
        content_type += "image/jpeg";
    else
    {
    }
    return content_type + SEP;
}

string handlerHttp(string& message){
    cout << "-----------------------------" << endl;
    cout << message << endl;

    string body = "<html> <body> <h1>hello World</h1></body></html>";

    string responce = "HTTP/1.0 200 OK" + SEP;

    responce += "Content-Length: " + to_string(body.size()) + SEP;

    responce += SEP;

    responce += body;

    return responce;
}

int main(int argc, char* argv[]){
    if(argc != 2)
        exit(USAGE_ERR);
    uint16_t port = atoi(argv[1]);
    unique_ptr<HttpServer> tsvr(new HttpServer(handlerHttp, port));
    tsvr->InitServer();
    tsvr->Start();

    return 0;
}